﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace InnovTech.Net.DataTransfer
{
    public abstract class DataTransferEventArgsBase : CancelEventArgs
    {
        public abstract DataTransferState State { get; }
    }


    public class DataTransferInitializedEventArgs : DataTransferEventArgsBase
    {
        public override DataTransferState State
        {
            get { return DataTransferState.Initialized; }
        }
    }

    public class DataTransferConnectingEventArgs : DataTransferEventArgsBase
    {
        public override DataTransferState State
        {
            get { return DataTransferState.Connecting; }
        }

        public bool IsNetworkAvaliable { get; set; }
        public bool IsServerAvaliable { get; set; }
    }

    public class DataTransferStartingEventArgs : DataTransferEventArgsBase
    {
        public override DataTransferState State
        {
            get { return DataTransferState.TransferStarting; }
        }
    }

    public class DataTransferingEventArgs : DataTransferEventArgsBase
    {
        public override DataTransferState State
        {
            get { return DataTransferState.Transfering; }
        }

        public long TotalLength { get; set; }
        public long Transfered { get; set; }
    }


    public class DataTransferCanceledEventArgs : DataTransferEventArgsBase
    {
        public override DataTransferState State
        {
            get { return DataTransferState.Canceled; }
        }
    }

    public class DataTransferErrorEventArgs : DataTransferEventArgsBase
    {

        public DataTransferErrorEventArgs(Exception exception)
            :this(exception, ErrorPolicy.Close)
        {
            InnerException = exception;
        }

        public DataTransferErrorEventArgs(Exception exception, ErrorPolicy errorHandlerType, TimeSpan retryInterval = default(TimeSpan))
        {
            InnerException = exception;
            ErrorHandlerType = errorHandlerType;
            RetryInterval = retryInterval;
        }

        public override DataTransferState State
        {
            get { return DataTransferState.Error; }
        }

        public Exception InnerException { get; private set; }
        public ErrorPolicy ErrorHandlerType { get; set; }
        public TimeSpan RetryInterval { get; set; }
    }

    public enum ErrorPolicy
    {
        Close,
        Retry,
        Other
    }

    public class DataTransferCompletedEventArgs : DataTransferEventArgsBase
    {
        public override DataTransferState State
        {
            get { return DataTransferState.TransferCompleted; }
        }
    }

    public class DataTransferStateChangedEventArgs : DataTransferEventArgsBase
    {

        public DataTransferStateChangedEventArgs(DataTransferState old, DataTransferState newState)
        {
            OldState = old;
            CurrentState = newState;
        }

        public override DataTransferState State
        {
            get { return CurrentState; }
        }

        public DataTransferState OldState
        {
            get;
            private set;
        }
        public DataTransferState CurrentState
        {
            get;
            private set;
        }

        public Exception Error
        {
            get;
            set;
        }
    }

}
